home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12135 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: solon.com!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 29 Mar 1996 06:08:52 -0600
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4jgjsk$sbp@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com> <4j6389$3iq@solutions.solon.com> <4ja3s4$par@solutions.solon.com> <4je1pp$g2r@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4je1pp$g2r@solutions.solon.com>,
  14. J. Kanze <kanze@gabi-soft.fr> wrote:
  15. >In article <4jckoq$a32@solutions.solon.com> Lawrence Kirby
  16. ><fred@genesis.demon.co.uk> writes:
  17. >
  18. >|> In article <4ja3s4$par@solutions.solon.com>
  19. >|>            kanze@lts.sel.alcatel.de "James Kanze US/ESC 60/3/141 #40763" writes:
  20. >
  21. >|> >I agree about not using any old arbitrary order, but the cv-qualifiers
  22. >|> >should definitly come *after* what they modify.  It is only in the
  23. >|> >declaration-specifier that you have any freedom.  In the declarator,
  24. >|> >the cv-qualifier *must* follow what it modifies.  So why do it any
  25. >|> >differently here.
  26. >
  27. >|> Personally I think it reads more clearly with the qualifier prior to the
  28. >|> type.
  29. >
  30. >Except when it is a pointer that is const, n'est-ce pas? :-)
  31.  
  32. When it's a pointer, we are talking about different syntactic units. The
  33. pointer clause is part of the declarator, not the specifier list.
  34. You have no choice, because the grammar is something like:
  35.  
  36. indirect-declarator:
  37.     pointer_opt direct-declarator
  38.     ... other productions
  39.  
  40. pointer:
  41.     * qualifier_opt pointer_opt
  42.     ... other productions
  43.  
  44. So to make the optional type qualifier bind with the pointer, you _must_ put it
  45. after the *, otherwise it is part of the specifier list to the left.
  46.  
  47. >I'll admit that it somehow `looks' more natural to put the const first,
  48. >at least, until you get used to the other alternative.  (This may be
  49. >related to the fact that we put adjectives in front of the noun in
  50. >English, and that we somehow feal that const is an adjective.)  I find
  51.  
  52. Le integer const!
  53.  
  54. We can't have someone living on French soil agree with an Englishman about
  55. where to place a qualifier.
  56.  
  57. >it more consistent to put the const after, however, since I have to do
  58. >so anyway in some cases.
  59.  
  60. Up to you!
  61. -- 
  62.